package com.ling.sdk.utils

import android.app.ActivityManager
import android.content.Context
import android.os.Process
import com.ling.sdk.app.App

/**
 * Created by MinF on 2018/7/26 0026.
 */
object ProcessUtil {

    @JvmStatic
    fun getProcessName(context: Context?, pid: Int): String? {
        (context?.getSystemService(Context.ACTIVITY_SERVICE) as? ActivityManager)?.runningAppProcesses?.forEach {
            if (it.pid == pid) return it.processName
        }
        return null
    }

    //是否是主进程
    @JvmStatic
    fun isMainProcess(context: Context?) = getProcessName(context, Process.myPid()) == App.app.packageName
}